package wangxiaotao.converter;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import wangxiaotao.bean.vo.RoomVO;
import wangxiaotao.entity.Room;
import wangxiaotao.enums.RoomStatue;

import java.util.List;

@Mapper(componentModel = "spring")
public interface RoomConverter {

    @Mappings({
            @Mapping(target = "roomStatue",source = "roomStatue.statue")
    })
    RoomVO toRoomVO(Room room);

    @Mappings({
            @Mapping(target = "roomStatue",expression = "java(getStatue(roomVO.getRoomStatue()))")
    })
    Room toRoom(RoomVO roomVO);

    List<RoomVO> toListRoomVO(List<Room> roomList);

    default RoomStatue getStatue(Integer statue){
        for (RoomStatue o: RoomStatue.values()){
            if (statue.equals(o.getStatue()))
                return o;
        }
        return null;
    }
}
